import { Injectable } from '@angular/core';
import * as _ from 'lodash';
import { Subject } from 'rxjs';
import { HttpService } from '@kylin/http';

@Injectable({
    providedIn: 'root'
})

export class UserService {
    private changeUser = new Subject();
    userObservable = this.changeUser.asObservable();
    user = {};

    constructor(private http: HttpService) {
    }

    fetchPersInfo(): Promise<any> {
        return new Promise((resolve, reject) => {
            this.http.get('/users/current')
                .then(res => {
                    if (res.resp_code === '10000') {
                        this.user = res.data;
                        resolve(res.data);
                    } else {
                        resolve({})
                    }
                })
                .catch(err => {
                    resolve({})
                })
        })
    }

    modifyPersInfo() {
        this.http.put('/users/me', { nickname: '' })
            .then(res => {

            })
            .catch(err => {

            })
    }

    send() {
        this.changeUser.next(''); // rxjs 发布模式
    }
}
